package com.bw.classfiy.mvvm.view;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.bw.classfiy.BR;
import com.bw.classfiy.R;
import com.bw.classfiy.databinding.ActivityParticularsBinding;
import com.bw.mvvm.entity.ClassFiyEntity;
import com.bw.classfiy.mvvm.viewmodel.ParticulareViewModel;
import com.bw.mvvm.custom.BottomCustom;
import com.bw.mvvm.mvvm.view.BaseActivity;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;
import java.util.List;

public class ParticularsActivity extends BaseActivity<ActivityParticularsBinding, ParticulareViewModel> {

    BottomCustom news, share, shopping;

    private ImageView particularsImg,back;
    private TextView particulaesTitle;
    private TextView particulaesMoney;
    private Button shoppingBotton;
    private List<ClassFiyEntity.DataBean> fiyEntity;


    @Override
    public int bindLayout() {
        return R.layout.activity_particulars;
    }

    @Override
    public int initVerable() {
        return BR.particulaes;
    }

    @Subscribe(sticky = true)
    public void getEventBus(ClassFiyEntity.DataBean classFiyEntity) {
        fiyEntity.add(classFiyEntity);
        LogUtils.e(classFiyEntity.getCategory_icon());
        if (classFiyEntity.getCategory_icon() != null) {
            Glide.with(this)
                    .load(classFiyEntity.getCategory_icon())
                    .into(particularsImg);
        }

        particulaesTitle.setText(classFiyEntity.getCategory_name());
        particulaesMoney.setText("￥1.00");

    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();
        EventBus.getDefault().register(this);
        news.setNomalImag(R.drawable.myflase)
                .setConten("店小二")
                .setSelImag(R.drawable.myflase)
                .setSelSize(5)
                .setNomalColor(Color.BLACK)
                .setNomalSize(5)
                .refresh();
        share.setNomalImag(R.drawable.icon_favorite_nor)
                .setConten("分享")
                .setSelImag(R.drawable.icon_favorite_nor)
                .setSelSize(5)
                .setNomalColor(Color.BLACK)
                .setNomalSize(5)
                .refresh();
        shopping.setNomalImag(R.drawable.btn_nav_cart_normal)
                .setConten("购物车")
                .setSelImag(R.drawable.btn_nav_cart_normal)
                .setSelSize(5)
                .setNomalColor(Color.BLACK)
                .setNomalSize(5)
                .refresh();
        shoppingBotton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventBus.getDefault().postSticky(fiyEntity);
                finish();
            }
        });
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

    }

    private void initView() {
        back = findViewById(R.id.back);
        particularsImg = (ImageView) findViewById(R.id.particulars_imag);
        particulaesTitle = (TextView) findViewById(R.id.particulaes_title);
        particulaesMoney = (TextView) findViewById(R.id.particulaes_money);
        news = findViewById(R.id.botton_news);
        share = findViewById(R.id.botton_share);
        shopping = findViewById(R.id.botton_shopping);
        shoppingBotton = (Button) findViewById(R.id.shopping_botton);
        fiyEntity = new ArrayList<>();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }



}
